// Tetris.cpp : 定义应用程序的入口点。
//
 
/*
记录于2016-5-29 星期日    由于闪屏过于显眼，采用双缓冲
 
*/
 
#include "stdafx.h"
#include "Tetris.h"
#include "windows.h"
#include <mmsystem.h>
#pragma comment(lib, "WINMM.LIB")//Windows多媒体相关应用程序接口
#define MAX_LOADSTRING 100
 
// 此代码模块中包含的函数的前向声明:
ATOM                MyRegisterClass(HINSTANCE hInstance);//注册窗口
BOOL                InitInstance(HINSTANCE, int);//初始化应用
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);//窗口处理
INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
 
// 全局变量:
HINSTANCE hInst;                                // 当前实例
TCHAR szTitle[MAX_LOADSTRING];                  // 标题栏文本
TCHAR szWindowClass[MAX_LOADSTRING];            // 主窗口类名
 
int APIENTRY _tWinMain(HINSTANCE hInstance,//应用程序当前实例句柄
                     HINSTANCE hPrevInstance,//应用程序其他实例句柄
                     LPTSTR    lpCmdLine,//指向程序命令行参数的指针
                     int       nCmdShow)//应用程序开始执行时窗口显示方式的整数值标识
{
    init_game();//初始化游戏
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);//避免编译器关于未引用参数的警告
 
    // TODO: 在此放置代码。
    MSG msg;
    HACCEL hAccelTable;
 
    // 初始化全局字符串
    LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadString(hInstance, IDC_TETRIS, szWindowClass, MAX_LOADSTRING);
    MyRegisterClass(hInstance);
 
    // 执行应用程序初始化:
    if (!InitInstance (hInstance, nCmdShow))
    {
        return FALSE;
    }
 
    hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_TETRIS));
 
    // 主消息循环:
    while (1)
    {
        if (PeekMessage(&msg,0,0,0,PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
            if (msg.message==WM_QUIT)
            {
                break;
            }
        }
        else
        {
            if ((GAME_STATE&2)!=0)
            {
                tCur = GetTickCount();//返回系统启动至今所经过的毫秒数
                if (tCur-tPre>g_speed)//超过反应时间
                {
 
                    int flag = CheckValide(curPosX,curPosY+1,bCurTeris);//判断下一行的情况
                    if (flag==1)//下落一行，并局部刷新窗口
                    {
                        curPosY++;
                        tPre = tCur;
                        HWND hWnd = GetActiveWindow();
                        InvalidateRect(hWnd,&rc_left,FALSE);
                        InvalidateRect(hWnd,&rc_right_top,FALSE);
                    }
                    else if (flag==-2)//方块降落到底
                    {
                        g_speed = t_speed;//设为正常速度
                        fillBlock();//填充矩形
                        checkComplite();//看是否可消去
                        setRandomT();//添加新方块
                        //重置坐标
                        curPosX = (NUM_X-4)>>1;
                        curPosY = 0;
                        HWND hWnd = GetActiveWindow();
                        //刷新矩形区域
                        InvalidateRect(hWnd,&rc_main,FALSE);
                    }
                    else if(flag==-3)//游戏结束
                    {
                        HWND hWnd = GetActiveWindow();
                        if (MessageBox(hWnd,L"胜败乃兵家常事，菜鸡请重新来过",L":时光机",MB_YESNO)==IDYES)
                        {
                            init_game();//重置游戏（重新开始）
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }
    }
 
    return (int) msg.wParam;
}
 
 
//
//  函数: MyRegisterClass()
//
//  目的: 注册窗口类。
//
//  注释:
//
//    仅当希望
//    此代码与添加到 Windows 95 中的“RegisterClassEx”
//    函数之前的 Win32 系统兼容时，才需要此函数及其用法。调用此函数十分重要，
//    这样应用程序就可以获得关联的
//    “格式正确的”小图标。
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
    WNDCLASSEX wcex;//窗口类对象
 
    wcex.cbSize = sizeof(WNDCLASSEX);//窗口大小
 
    wcex.style          = CS_HREDRAW | CS_VREDRAW; //风格
    wcex.lpfnWndProc    = WndProc; //过程处理函数
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;//当前实例句柄
    wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TETRIS));//窗口的图标
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);//箭头光标
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);//背景
    wcex.lpszMenuName   = MAKEINTRESOURCE(IDC_TETRIS);//菜单
    wcex.lpszClassName  = szWindowClass;//窗口类名
    wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));//小图标
 
    return RegisterClassEx(&wcex);
}
 
//
//   函数: InitInstance(HINSTANCE, int)
//
//   目的: 保存实例句柄并创建主窗口
//
//   注释:
//
//        在此函数中，我们在全局变量中保存实例句柄并
//        创建和显示主程序窗口。
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;
 
   hInst = hInstance; // 将实例句柄存储在全局变量中
 
 //创建窗口
   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
   if (!hWnd)
   {
      return FALSE;
   }
 
   ShowWindow(hWnd, nCmdShow);//显示窗口
   UpdateWindow(hWnd);//更新窗口
 
   return TRUE;
}
 
//
//  函数: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  目的: 处理主窗口的消息。
//
//  WM_COMMAND  - 处理应用程序菜单
//  WM_PAINT    - 绘制主窗口
//  WM_DESTROY  - 发送退出消息并返回
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    PAINTSTRUCT ps;//画笔信息结构体
    HDC hdc;//设备环境句柄
    int nWinx,nWiny,nClientX,nClientY;
    int posX,posY;
    RECT rect;
    HMENU hSysmenu;//菜单窗口的句柄
    switch (message)
    {
    case WM_CREATE:
         
 
        GetWindowRect(hWnd,&rect);//创建窗口
        //窗口的大小
        nWinx = 530;
        nWiny = 680;
        //计算窗口在屏幕中的位置
        posX = GetSystemMetrics(SM_CXSCREEN);
        posY = GetSystemMetrics(SM_CYSCREEN);
        posX = (posX - nWinx)>>1;
        posY = (posY - nWiny)>>1;
        GetClientRect(hWnd,&rect);//获取窗口客户区大小
        nClientX = rect.right - rect.left;
        nClientY = rect.bottom - rect.top;
 
        MoveWindow(hWnd,posX,posY,530,680,TRUE);//设置窗口位置和大小
        hSysmenu = GetSystemMenu(hWnd,false);//获取菜单句柄
        AppendMenu(hSysmenu,MF_SEPARATOR,0,NULL);//添加分割线
        AppendMenu(hSysmenu,0,IDM_DIFF,L"难度选择");//添加难度菜单
        break;
    case WM_COMMAND://菜单事件
        wmId    = LOWORD(wParam);//低位字节
        wmEvent = HIWORD(wParam);//高位字节
        // 分析菜单选择:
        switch (wmId)
        {
        case IDM_ABOUT://关于
            DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);//弹出窗口
            break;
        case IDM_EXIT://退出
            DestroyWindow(hWnd);
            break;
        case ID_dif1://难度1
            selectDiffculty(hWnd,1);
            break;
        case ID_dif2://难度2
            selectDiffculty(hWnd,2);
            break;
        case ID_dif3://难度3
            selectDiffculty(hWnd,3);
            break;
        case ID_LAYOUT1://布局1
            selectLayOut(hWnd,1);
            break;
        case ID_LAYOUT2://布局2
            selectLayOut(hWnd,2);
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);//默认处理方式
        }
        break;
    case WM_KEYDOWN://键盘事件
        hdc = GetDC(hWnd);
        InvalidateRect(hWnd,NULL,false);
        switch(wParam)
        {
        case VK_LEFT://左键
            curPosX--;
            if(CheckValide(curPosX,curPosY,bCurTeris)!=1)
            {
                curPosX++;
            }
            break;
        case VK_RIGHT://右键
            curPosX++;
            if(CheckValide(curPosX,curPosY,bCurTeris)!=1)
            {
                curPosX--;
            }
            break;
        case VK_UP://上键，旋转方块
            RotateTeris(bCurTeris);
            break;
        case VK_DOWN://下键，快速下降
            if (g_speed==t_speed)
                g_speed =10 ;
            else
                g_speed = t_speed;
            //outPutBoxInt(g_speed);
            break;
        case 'W'://旋转
            RotateTeris(bCurTeris);
            break;
        case 'A'://左移
            curPosX--;
            if(CheckValide(curPosX,curPosY,bCurTeris)!=1)
            {
                curPosX++;
            }
            break;
        case 'D'://右移
            curPosX++;
            if(CheckValide(curPosX,curPosY,bCurTeris)!=1)
            {
                curPosX--;
            }
            break;
         
        case 'S'://快速下落
            if (g_speed==t_speed)
                g_speed =10 ;
            else
                g_speed = t_speed;
            //outPutBoxInt(g_speed);
            break;
        default:
            break;
        }
 
    case WM_PAINT://窗口绘制函数
        hdc = BeginPaint(hWnd, &ps);
        // TODO: 在此添加任意绘图代码...
        DrawBackGround(hdc);
        EndPaint(hWnd, &ps);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
 
// “关于”框的消息处理程序。
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    UNREFERENCED_PARAMETER(lParam);//消除编译器警告
    switch (message)
    {
    case WM_INITDIALOG:
        return (INT_PTR)TRUE;
 
    case WM_COMMAND:
        if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
        {
            EndDialog(hDlg, LOWORD(wParam));//停止对话框
            return (INT_PTR)TRUE;
        }
        break;
    }
    return (INT_PTR)FALSE;
}
 
 
void drawBlocked(HDC mdc)//绘制砖块
{
    int i,j;
 
    HBRUSH hBrush = (HBRUSH)CreateSolidBrush(RGB(255,255,0));//创建画刷句柄
     
    SelectObject(mdc,hBrush);//选择一对象到指定的设备上下文环境中
 
    for (i=0;i<NUM_Y;i++)
    {
        for (j=0;j<NUM_X;j++)
        {
            if (g_hasBlocked[i][j])
            {
                Rectangle(mdc,BORDER_X+j*BLOCK_SIZE,BORDER_Y+i*BLOCK_SIZE,
                    BORDER_X+(j+1)*BLOCK_SIZE,BORDER_Y+(i+1)*BLOCK_SIZE
                    );
            }//绘制存在方块的区域
        }
    }
    DeleteObject(hBrush);//删除画刷对象
}
 
 //检查方块矩阵位置是否合法
int CheckValide(int startX,int startY,BOOL bTemp[4][4])
{
    int i,j;
    for (i=3;i>=0;i--)
    {
        for (j=3;j>=0;j--)
        {
            if(bTemp[i][j])
            {
            	//检查是否越界
                if (j+startX<0||j+startX>=NUM_X)
                {
                    return -1;
                }
                if (i+startY>=NUM_Y)
                {
                    return -2;
                }
                //检查方块是否重叠
                if (g_hasBlocked[i+startY][j+startX])
                {
                    //outPutBoxInt(j+startY);
                    if (curPosY==0)
                    {
                        return -3;
                    }
                    return -2;
                }
            }
        }
    }
    //MessageBox(NULL,L"这里",L"as",MB_OK);
    //outPutBoxInt(curPosY);
    return 1;
}
 
void checkComplite()//检查一行能否消去
{
    int i,j,k,count=0;
    for (i=0;i<NUM_Y;i++)
    {
        bool flag = true;
        for (j=0;j<NUM_X;j++)
        {
            if(!g_hasBlocked[i][j])//有一个为空
            {
                flag = false;
            }
        }
        if (flag)//若该行已满
        {
            count++;//记录消去的行数
            for (j=i;j>=1;j--)
            {
                for (k=0;k<NUM_X;k++)
                {
                    g_hasBlocked[j][k] = g_hasBlocked[j-1][k];//将该行下移
                }
                 
            }
            drawCompleteParticle(i);//绘制特效
            Sleep(300);//游戏暂停0.3秒
             
            PlaySound(_T("coin.wav"),NULL,SND_FILENAME|SND_ASYNC);//播放音效"coin.wav"
        }
    }
    GAME_SCORE += int(count*1.5);//更新游戏分数
}
 
 
 
VOID outPutBoxInt(int num)//弹窗显示数字
{
    TCHAR szBuf[1024];
    LPCTSTR str = TEXT("%d");
    wsprintf(szBuf,str,num);
    MessageBox(NULL,szBuf,L"aasa",MB_OK);
}
 
VOID outPutBoxString(TCHAR str[1024])//弹窗显示文字
{
    TCHAR szBuf[1024];
    LPCTSTR cstr = TEXT("%s");
    wsprintf(szBuf,cstr,str);
    MessageBox(NULL,szBuf,L"aasa",MB_OK);
}
 
 
 
 
void setRandomT()//设置随机方块
{
    int rd_start = RandomInt(0,sizeof(state_teris)/sizeof(state_teris[0]));
    int rd_next = RandomInt(0,sizeof(state_teris)/sizeof(state_teris[0]));
    //outPutBoxInt(rd_start);
    //outPutBoxInt(rd_next);
    //outPutBoxInt(rd_start);
    if (GAME_STATE==0)//第一次添加方块的情况
    {
        GAME_STATE = GAME_STATE | 0x0001;
        //outPutBoxInt(GAME_STATE);
        memcpy(bCurTeris,state_teris[rd_start],sizeof(state_teris[rd_start]));//复制分块数据
        memcpy(bNextCurTeris,state_teris[rd_next],sizeof(state_teris[rd_next]));
    }
    else
    {
        memcpy(bCurTeris,bNextCurTeris,sizeof(bNextCurTeris));
        memcpy(bNextCurTeris,state_teris[rd_next],sizeof(state_teris[rd_next]));
    }
     
}
//初始化游戏
void init_game()
{
    GAME_SCORE = 0;//清零游戏分数
    setRandomT();//添加初始方块
    //初始坐标(顶部中间)
    curPosX = (NUM_X-4)>>1;
    curPosY = 0;
     
     
    memset(g_hasBlocked,0,sizeof(g_hasBlocked));//清空已存在的方块
    rc_left.left = 0;
    rc_left.right = SCREEN_LEFT_X;
    rc_left.top = 0;
    rc_left.bottom = SCREEN_Y;
 
    rc_right.left = rc_left.right+BORDER_X;
    rc_right.right = 180+rc_right.left;
    rc_right.top = 0;
    rc_right.bottom = SCREEN_Y;
 
    rc_main.left = 0;
    rc_main.right = SCREEN_X;
    rc_main.top = 0;
    rc_main.bottom = SCREEN_Y;
 
    rc_right_top.left = rc_right.left;
    rc_right_top.top = rc_right.top;
    rc_right_top.right = rc_right.right;
    rc_right_top.bottom = (rc_right.bottom) / 2;
 
    rc_right_bottom.left = rc_right.left;
    rc_right_bottom.top = rc_right_top.bottom+BORDER_Y;
    rc_right_bottom.right = rc_right.right;
    rc_right_bottom.bottom = rc_right.bottom;
     
    g_speed = t_speed = 1000-GAME_DIFF*280;//根据游戏难度设置速度
}
 
void fillBlock()//将方块的数据填充进矩阵
{
    int i,j;
    for (i=0;i<4;i++)
    {
        for (j=0;j<4;j++)
        {
            if(bCurTeris[i][j])
            {
                g_hasBlocked[curPosY+i][curPosX+j] = 1;
            }
        }
    }
}
 
void RotateTeris(BOOL bTeris[4][4])//旋转方块
{
    BOOL bNewTeris[4][4];//临时矩阵副本
    int x,y;
    for (x=0;x<4;x++)
    {
        for(y=0;y<4;y++)
        {
            bNewTeris[x][y] = bTeris[3-y][x];
            //逆时针：
            //bNewTeris[x][y] = bTeris[y][3-x];
        }
    }
    if (CheckValide(curPosX,curPosY,bNewTeris)==1)//如果新方块矩阵位置不冲突，则进行旋转
    {
        memcpy(bTeris,bNewTeris,sizeof(bNewTeris));
    }
 
}
 
int RandomInt(int _min,int _max)//获得随机整数
{
    srand((rd_seed++)%65532+GetTickCount());
    return _min+rand()%(_max-_min);
}
 
VOID DrawTeris(HDC mdc)//绘制正在移动的砖块
{
 
    int i,j;
    HPEN hPen = (HPEN)GetStockObject(BLACK_PEN);//画笔句柄
    HBRUSH hBrush = (HBRUSH)GetStockObject(WHITE_BRUSH);//画刷句柄
    SelectObject(mdc,hPen);//选择画笔对象
    SelectObject(mdc,hBrush);//选择画刷对象
    for (i=0;i<4;i++)
    {
        for (j=0;j<4;j++)
        {
            if(bCurTeris[i][j])
            {
                Rectangle(mdc,(j+curPosX)*BLOCK_SIZE+BORDER_X,(i+curPosY)*BLOCK_SIZE+BORDER_Y,(j+1+curPosX)*BLOCK_SIZE+BORDER_X,(i+1+curPosY)*BLOCK_SIZE+BORDER_Y);
            }
        }
    }
    drawBlocked(mdc);//绘制已存在砖块
    DeleteObject(hPen);//释放对象
    DeleteObject(hBrush);//释放对象
}
 
VOID DrawBackGround(HDC hdc)//绘制背景
{
 
    HBRUSH hBrush = (HBRUSH)GetStockObject(GRAY_BRUSH);//画刷句柄
    HDC mdc = CreateCompatibleDC(hdc);//创造适配环境
    HBITMAP hBitmap = CreateCompatibleBitmap(hdc,SCREEN_X,SCREEN_Y);//位图句柄
 
    SelectObject(mdc,hBrush);//选择画笔对象
    SelectObject(mdc,hBitmap);//选择位图对象
 
    HBRUSH hBrush2 = (HBRUSH)GetStockObject(WHITE_BRUSH);//画刷句柄
    FillRect(mdc,&rc_main,hBrush2);
    Rectangle(mdc,rc_left.left+BORDER_X,rc_left.top+BORDER_Y,rc_left.right,rc_left.bottom);
    Rectangle(mdc,rc_right.left+BORDER_X,rc_right.top+BORDER_Y,rc_right.right,rc_right.bottom);
    DrawTeris(mdc);
    drawNext(mdc);//绘制下一个方块预览
    drawScore(mdc);//绘制分数文字
    ::BitBlt(hdc,0,0,SCREEN_X,SCREEN_Y,mdc,0,0,SRCCOPY);
    //释放相关对象
    DeleteObject(hBrush);
    DeleteDC(mdc);
    DeleteObject(hBitmap);
    DeleteObject(hBrush2);
 
 
    //  int x,y;
    //  HPEN hPen = (HPEN)GetStockObject(NULL_PEN);
    //  HBRUSH hBrush = (HBRUSH)GetStockObject(GRAY_BRUSH);
    //  SelectObject(hdc,hPen);
    //  SelectObject(hdc,hBrush);
    //  for (x = 0;x<NUM_X;x++)
    //  {
    //      for(y=0;y<NUM_Y;y++)
    //      {
    //          Rectangle(hdc,BORDER_X+x*BLOCK_SIZE,BORDER_Y+y*BLOCK_SIZE,
    //              BORDER_X+(x+1)*BLOCK_SIZE,
    //              BORDER_Y+(y+1)*BLOCK_SIZE);
    //      }
    //  }
}
 
void drawNext(HDC hdc)//画下一个方块的预览图
{
    int i,j;
    HBRUSH hBrush = (HBRUSH)CreateSolidBrush(RGB(0,188,0));
    SelectObject(hdc,hBrush);
    for (i=0;i<4;i++)
    {
        for (j=0;j<4;j++)
        {
            if(bNextCurTeris[i][j])
            {
                Rectangle(hdc,rc_right_top.left+BLOCK_SIZE*(j+1),rc_right_top.top+BLOCK_SIZE*(i+1),rc_right_top.left+BLOCK_SIZE*(j+2),rc_right_top.top+BLOCK_SIZE*(i+2));
            }
        }
    }
    HFONT hFont = CreateFont(30,0,0,0,FW_THIN,0,0,0,UNICODE,0,0,0,0,L"微软雅黑");//字体句柄
    SelectObject(hdc,hFont);
    SetBkMode(hdc,TRANSPARENT);//背景混合模式
    SetBkColor(hdc,RGB(255,255,0));//背景色
    RECT rect; //绘制区域
    rect.left = rc_right_top.left+40;
    rect.top = rc_right_top.bottom -150;
    rect.right = rc_right_top.right;
    rect.bottom = rc_right_top.bottom;
    DrawTextW(hdc,TEXT("下一个"),_tcslen(TEXT("下一个")),&rect,0);//绘制文字
    DeleteObject(hFont);
    DeleteObject(hBrush);
}
 
void drawScore(HDC hdc)//分数绘制函数
{
    HFONT hFont = CreateFont(30,0,0,0,FW_THIN,0,0,0,UNICODE,0,0,0,0,L"微软雅黑");//字体句柄
    SelectObject(hdc,hFont);
    SetBkMode(hdc,TRANSPARENT);//背景混合模式
    SetBkColor(hdc,RGB(255,255,0));//背景色
    //定义绘制区域
    RECT rect;
    rect.left = rc_right_bottom.left;
    rect.top = rc_right_bottom.top;
    rect.right = rc_right_bottom.right;
    rect.bottom = rc_right_bottom.bottom;
    TCHAR szBuf[30];
    LPCTSTR cstr = TEXT("当前难度：%d");
    wsprintf(szBuf,cstr,GAME_DIFF);
    DrawTextW(hdc,szBuf,_tcslen(szBuf),&rect,DT_CENTER | DT_VCENTER);
 
    RECT rect2;
    rect2.left = rc_right_bottom.left;
    rect2.top = rc_right_bottom.bottom/2+100;
    rect2.right = rc_right_bottom.right;
    rect2.bottom = rc_right_bottom.bottom;
    TCHAR szBuf2[30];
    LPCTSTR cstr2 = TEXT("得分：%d");
    wsprintf(szBuf2,cstr2,GAME_SCORE);
    //outPutBoxInt(sizeof(szBuf));
    DrawTextW(hdc,szBuf2,_tcslen(szBuf2),&rect2,DT_CENTER | DT_VCENTER);
 
    DeleteObject(hFont);
}
 
int selectDiffculty(HWND hWnd,int diff)//困难度选择菜单
{
    TCHAR szBuf2[30];
    LPCTSTR cstr2 = TEXT("确认选择难度 %d 吗？");
    wsprintf(szBuf2,cstr2,diff);
    if (MessageBox(hWnd,szBuf2,L"难度选择",MB_YESNO)==IDYES)
    {
        GAME_DIFF = diff;
        InvalidateRect(hWnd,&rc_right_bottom,false);
        GAME_STATE |=2;
        init_game();
        return GAME_DIFF;
    }
    return -1;
}
 
int selectLayOut(HWND hWnd,int layout)//选择布局
{
    NUM_X = 10*layout;
    NUM_Y = 20*layout;
    BLOCK_SIZE = 30/layout;
    GAME_STATE|=2;
    InvalidateRect(hWnd,&rc_right_bottom,false);
    init_game();
    return layout;
}
 
void drawCompleteParticle(int line)//绘制特效
{
    HWND hWnd = GetActiveWindow();
    HDC hdc = GetDC(hWnd);
    HBRUSH hBrush = (HBRUSH)GetStockObject(GRAY_BRUSH);
    HPEN hPen = (HPEN)CreatePen(PS_DOT,1,RGB(255,255,0));
    SelectObject(hdc,hBrush);
    SelectObject(hdc,hPen);
    Rectangle(hdc,BORDER_X,
        BORDER_Y+line*BLOCK_SIZE,
        BORDER_X+NUM_X*BLOCK_SIZE,
        BORDER_Y+BLOCK_SIZE*(1+line));
    DeleteObject(hBrush);
    DeleteObject(hPen);
}